#include "AppUser.h"

bool AppUser::insertUser(User& newUser){
	unordered_map<long long, User*>::iterator it = users.find(newUser.userId);
	if (it != users.end()){
		cout << "Conflict User Id, already exist userId: " << newUser.userId << endl;
		return false;
	}
	else{
		users.insert(make_pair(newUser.userId, &newUser));
		return true;
	}
}
bool AppUser::deleteUser(long long userId){
	unordered_map<long long, User*>::iterator it = users.find(userId);
	if (it == users.end()){
		cout << "no such user: " << userId << endl;
		return false;
	}
	else{
		users.erase(it);
		cout << "successfully delete ad content: " << userId << endl;
		return true;
	}
}
pair<User*, bool> AppUser::searchUser(long long userId){
	unordered_map<long long, User*>::iterator it = users.find(userId);
	if (it == users.end()){
		cout << "no such ad content in our database, adId:" << userId << endl;
		return make_pair(it->second, false);
	}
	else{
		return make_pair(it->second, true);
	}

}